package org.example.taskmaster.fragments;

import android.content.Context;
import android.widget.Toast;


public class DetailsFragmentFactory {
	// DetailsFragment types
	public static final String NEW_TASK = "New Task";
	public static final String ALL_TASKS = "All Tasks";
	public static final String SELECT_LIST = "Select List";
	public static final String EDIT_TASK = "Edit Task";
	public static final String TASK_DETAIL = "Task Detail";
	public static final String TASK_LIST = "Task List";
	public static final String UPCOMING_TASKS = "Upcoming Tasks";

	// store context for calls to Toast
	private static Context context;
	public static void setContext(Context c) {
		context = c;
	}
	
	// Dictate what tabs are shown
	public static String[] getTabs() {
		String [] tabs = {UPCOMING_TASKS, SELECT_LIST, ALL_TASKS, NEW_TASK};
		return tabs;
	}

	// Factory Methods 
	public static DetailsFragment getDetailsFragment(String type) {
		if (type.equals(NEW_TASK)) {
			return new EditTaskFragment();
		} else if (type.equals(ALL_TASKS)) {
			return new TaskListFragment(null);
		} else if (type.equals(UPCOMING_TASKS)) {
			return new TaskListFragment("upcoming");
		} else if (type.equals(SELECT_LIST)) {
			return new ListSelectFragment();
		}
		// default: show list select
		else {
			String message = "Invalid input: getDetailsFragment(String)";
			Toast.makeText(context.getApplicationContext(), message, Toast.LENGTH_SHORT).show();
			return new ListSelectFragment();
		}
	}
	public static DetailsFragment getDetailsFragment(String type, Long id) {
		if (type.equals(EDIT_TASK)) {
			return new EditTaskFragment(id);
		} else if (type.equals(TASK_DETAIL)) {
			return new TaskDetailsFragment(id);
		}
		// default: show list select
		else {
			String message = "Invalid input: getDetailsFragment(String, Long)";
			Toast.makeText(context.getApplicationContext(), message, Toast.LENGTH_SHORT).show();
			return new ListSelectFragment();
		}
	}
	public static DetailsFragment getDetailsFragment(String type, String list) {
		if (type.equals(TASK_LIST)) {
			return new TaskListFragment(list);
		}
		// default: show list select
		else {
			String message = "Invalid input: getDetailsFragment(String, String)";
			Toast.makeText(context.getApplicationContext(), message, Toast.LENGTH_SHORT).show();
			return new ListSelectFragment();
		}
	}

}
